package ltd.jdsoft.cute.bank.helper;

import com.alibaba.fastjson.JSONObject;

import ltd.jdsoft.cute.httpclient.HttpInvoker;
import ltd.jdsoft.cute.httpclient.model.HttpResponse;

/**
 * 调用阿里银行卡接口获取
 * 
 * @author zhengzhq
 *
 */
public class AliBankChecker {

  // 阿里巴巴银行卡号检测归属银行接口
  private static final String url =
      "https://ccdcapi.alipay.com/validateAndCacheCardInfo.json?cardNo=%s&cardBinCheck=true";

  /**
   * 根据银行卡号获取对应的银行名称
   * 
   * @param cardNo
   * @return
   */
  public static Result getBankBinByCardNo(String cardNo) {
    String invokeUrl = String.format(url, cardNo);
    HttpResponse response = HttpInvoker.doGet(invokeUrl);

    return JSONObject.parseObject(response.getResponse(), Result.class);
  }

  public static class Result {
    // 卡号是否有效
    private boolean validated;
    // 卡类型
    private String cardType;
    // 归属银行
    private String bank;

    public boolean isValidated() {
      return validated;
    }

    public void setValidated(boolean validated) {
      this.validated = validated;
    }

    public String getCardType() {
      return cardType;
    }

    public void setCardType(String cardType) {
      this.cardType = cardType;
    }

    public String getBank() {
      return bank;
    }

    public void setBank(String bank) {
      this.bank = bank;
    }
  }
}
